#指派问题
import numpy as np
from scipy.optimize import linear_sum_assignment

def printf(row_ind,col_ind):#输出
    print("最优结果指派：")
    for i in range(len(row_ind)):
        print("任务",row_ind[i]+1,"->人员",col_ind[i]+1,end='; ')
    print()

#擅长程度矩阵
goodAt =np.array([[15.15,14.12,16.46,8.77,9.79],
[14.86,10.63,13.89,7.63,8.91],
[7.84,5.53,6.34,15.31,12.92],
[13.10,10.92,19.00,15.90,14.18],
[3.42,1.94,2.68,3.73,5.09],])

row_ind,col_ind=linear_sum_assignment(goodAt)
# print(row_ind)#开销矩阵对应的行索引
# print(col_ind)#对应行索引的最优指派的列索引
# print(goodAt[row_ind,col_ind])#提取每个行索引的最优指派列索引所在的元素，形成数组
print("总用时：",goodAt[row_ind,col_ind].sum())#数组求和
printf(row_ind,col_ind)



# [[15.15,14.12,16.46,8.77,9.79],
# [14.86,10.63,13.89,7.63,8.91],
# [7.84,5.53,6.34,15.31,12.92],
# [13.10,10.92,19.00,15.90,14.18],
# [3.42,1.94,2.68,3.73,5.09],]
